<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增考勤')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<style>
    .jltable{
        margin: auto;
    }
    .jltable th,td{
        min-height: 40px;
        min-width: 50px;
        border: 1px solid #eee;
        padding: 10px;
    }
</style>
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-kq-add">
        <h4 class="form-header h4" style="margin-top: 30px">考勤管理</h4>
        <table class="jltable">
            <tbody>
                    <tr>
                        <td><label class="control-label is-required">名字</label></td>
                        <td>
                            <select  class="form-control" id="name_select"></select>
                            <input name="name" class="form-control" type="hidden" required>
                        </td>
                        <td><label class="control-label">状态</label></td>
                        <td><input name="status" class="form-control" type="text"></td>


                    </tr>
                    <tr>
                        <td><label class="control-label">正常（次）</label></td>
                        <td><input name="zc" class="form-control" type="text"></td>
                        <td><label class="control-label">早退（次）</label></td>
                        <td><input name="zt" class="form-control" type="text"></td>
                    </tr>

                    <tr>
                        <td><label class="control-label">迟到（次）</label></td>
                        <td><input name="cd" class="form-control" type="text"></td>
                        <td><label class="control-label">异常（次）</label></td>
                        <td><input name="yc" class="form-control" type="text"></td>
                    </tr>

                    <tr>
                        <td><label class="control-label">加班（时）</label></td>
                        <td><input name="jb" class="form-control" type="text">

                        <td><label class="control-label">外出（次）</label></td>
                        <td><input name="wc" class="form-control" type="text"></td>
                    </tr>
                    <tr>
                        <td><label class="control-label">应上班（天）</label></td>
                        <td><input name="ysb" class="form-control" type="text"></td>
                        <td><label class="control-label">已上班（天）</label></td>
                        <td><input name="ysb1" class="form-control" type="text"></td>
                    </tr>
                    <tr>
                        <td><label class="control-label">说明：</label></td>
                        <td colspan="3"><textarea name="sm" class="form-control"></textarea></td>
                    </tr>
            </tbody>
        </table>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var prefix = ctx + "lwpq/kq"
    $("#form-kq-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-kq-add').serialize());
        }
    }
    $(function (){
        function formatRepo(repo){
            return  repo.name || repo.text;
        }
        function formatRepoSelection(repo){
            return  repo.name || repo.text;
        }

        $('#name_select').select2({
            ajax:{
                url: ctx + 'lwpq/jl/list',
                type:'post',
                dataType:'json',
                data:function (params) {
                    let query = {
                        name:params.term,
                        zt:'',
                    }
                    return query;
                },
                processResults : function (data){
                    let res = new Array();
                    data.rows.forEach(value => {
                        res.push({
                            id : value.id,
                            text : value.name,
                            ob:value
                        })
                    })
                    return {
                        results : res
                    };
                },
                minimumInputLength : 1,
                maximumInputLength : 20,
                templateResult : formatRepo,
                templateSelection : formatRepoSelection,
            }
        })
        $('#name_select').on('select2:select', function (e) {
            // 处理业务
            let ob =  e.params.data.ob;
            $("input[name='name']").val(ob.name);
        });
    })
</script>
</body>
</html>